import { mapGetters } from 'vuex';
import { differenceBy } from 'lodash-es';
import { splitOrgNames } from 'jdf-util';
import { DocNumberService } from 'jdf-jssdk';
import { messageAlert } from '@/api/utils/pc-message';
import { unitsSecrets, switchDeptCode } from '@/utils/enum';
import { bizServiceURL } from '@/api/utils/constants';

const partyFileMixins = {
  methods: {
    /**
     * 主办部门提示
    */
    promptMessage(deptName) {
      const deptsName = unitsSecrets.find(time => time.value === deptName);
      const orgName = unitsSecrets.filter(time => time.label !== deptsName.label)?.map(time => time.label);
      if (this.isDraftTodo) {
        messageAlert(`目前您正以${deptsName.label}身份起草\n`
            + `文件，若需以${orgName.join('，')}身份\n`
            + '起草，请修改主办单位！', 'warning', false);
      }
    },
    // 切换身份信息提示
    administrationMessage(deptName) {
      if (switchDeptCode === this.orgCode && this.nodeId === 'draft') {
        const orgName = differenceBy(splitOrgNames(this.orgName), [deptName]).join('、');
        messageAlert(`目前您正在以${deptName}身份起草文件，`
            + `若想以${orgName}`
            + '人员身份起草文件，请点击切换身份按钮！', 'warning', false);
      }
    },
    /**
     * 根据主办部门切换部门获取代字
    */
    serialNumber(units) {
      // 查询文种代字
      return new DocNumberService(bizServiceURL).getCrownWord(
        this.taskInfo.processDefinitionKey,
        this.taskOwnerOrgCode,
        units ?? '0'
      );
    },
    /**
     * 根据主办部门获取代字
    */
    getInFormation() {
      // 查询文种代字
      return new DocNumberService(bizServiceURL).getCrownWord(
        this.taskInfo.processDefinitionKey,
        this.orgCode,
      );
    }
  },
  computed: {
    ...mapGetters(['orgName', 'orgCode'])
  },
};
export default partyFileMixins;
